#include<bits/stdc++.h>
using namespace std;
int T;
int m,n,L,V;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--){
        int ans=0,k=0;
        cin>>n>>m>>L>>V;
        int d[n+1],v[n+1],a[n+1];
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        bool used[m+1];
        int p[m+1];
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        sort(p+1,p+1+m);
        memset(used,0,sizeof(used));
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V&&d[i]<=p[m]){
                    ans++;
                }
            }

        }
        if(ans==0){
            cout<<ans<<" "<<m<<endl;
        }else{
            cout<<ans<<" "<<m-1<<endl;
        }
    }
    return 0;
}
